/* << fastinsert report library >> GridBase.cpp  Nov 1, 2010
 *
 * 	http://code.google.com/p/libfir
 *
 * Copyright (c) 2005 Pavlo Drobov (drobov.pavel@gmail.com)
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#include <stdio.h>
#include <string.h>

#include "Debug.h"
#include "GridBase.h"


#ifndef MIN
#define MIN(x,y) (x<y ? x:y)
#endif

namespace dasco
{
namespace report
{

RowSet::RowSet(const char* __outline)
	:outline(__outline)
{
}

RowSet::~RowSet()
{
}

ICell* RowSet::at (unsigned indx) const
{
	if (indx >= size())
		return NULL;
	setIteratorToBegin();
	int k= indx;
	while(k--)
		midge++;
	return *midge;
}

ICell* RowSet::operator  [] (unsigned indx) const
{
	return at(indx);
}


RowSetHeader::RowSetHeader(const char* __outline)
	:RowSet(__outline)
{
}

///////////////////////////////////////

GridBase::GridBase(const char* __outline)
	:outline(__outline)
{
}

GridBase::~GridBase()
{
}



void GridBase::addRow(IRowSet* rowset)
{
	push_back(rowset);
}


}}


void raiseMessageBox(const char*);


/////////// C API ////////////////
extern "C"
{
#define OUTLINE_CHECK(outline)  outline

using namespace dasco::report;

typedef RowSet			* RowSetHandle;
typedef GridBase		* GridBaseHandle;

DLL_EXPORT HANDLE getNewGrid(const char* outline)
{
	return  new GridBase(OUTLINE_CHECK(outline));
}


DLL_EXPORT void releaseGrid(HANDLE gridBaseHandle)
{
	delete (GridBaseHandle)gridBaseHandle;
}


DLL_EXPORT HANDLE getNewRowSet(const char* outline)
{
	  return  new RowSet(OUTLINE_CHECK(outline));
}

DLL_EXPORT HANDLE getNewRowSetHeader(const char* outline)
{
	  return  new RowSetHeader(OUTLINE_CHECK(outline));
}


DLL_EXPORT void addColumnText(HANDLE rowSet, const char* txt)
{
	if(rowSet)
		((RowSetHandle)rowSet)->addColumn(txt);
}

DLL_EXPORT void addColumnInt(HANDLE rowSet, int value)
{
	if(rowSet)
		((RowSetHandle)rowSet)->addColumn(value);
}

DLL_EXPORT void addColumnFloat(HANDLE rowSet, float value)
{
	if(rowSet)
		((RowSetHandle)rowSet)->addColumn(value);
}

DLL_EXPORT void addRowSet(HANDLE grid, HANDLE rowSet)
{
	if(grid)
		((GridBaseHandle)grid)->addRow((RowSetHandle)rowSet);
}

} //end extern "C"

